/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
  */
package be.khk.lesson;

import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;



/**
 *
 * @author Yorre
 */
@ManagedBean
@RequestScoped
public class PostcodeController {
    
    private int id;
    private String postcode;
    private String naam;
    private String up;
    private String structuur;

    public void setStructuur(String structuur) {
        this.structuur = structuur;
    }

    public String getStructuur() {
        return structuur;
    }
    public void setId(int id) {
        this.id = id;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    public void setNaam(String naam) {
        this.naam = naam;
    }

    public void setUp(String up) {
        this.up = up;
    }

    public int getId() {
        return id;
    }

    public String getPostcode() {
        return postcode;
    }

    public String getNaam() {
        return naam;
    }

    public String getUp() {
        return up;
    }
    
    
    /**
     * Creates a new instance of PostcodeController
     */
    public PostcodeController() {
    }
    
    public List<Postcode> getPostcodes(){
        
        EntityManagerFactory emf = null;
        try {
            emf = Persistence.createEntityManagerFactory("Awesome_RD_TravelshopPU");
//let op: gebruik hier de juiste naam van de persistence unit 
//(zoek op in persistence.xml)

           EntityManager em2 = emf.createEntityManager();
            List<Postcode> postcodes = em2.createQuery("select p from Postcode p").getResultList();
            return postcodes;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            emf.close();
        }



    }
    
    
}
